package com.shruijin.wy.thread.action;

import com.shruijin.wy.thread.notify.ThreadNotify;
import com.shruijin.wy.thread.signal.Signal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MathAction extends SimpleAction {

    //Signal signal = new Signal();
    ThreadNotify threadNotify = new ThreadNotify();
    Logger LOGGER  = LoggerFactory.getLogger(this.getClass());

    public void multi(int val,String threadName){
        LOGGER.info("{} : {} multi {}",threadName,val);
        value *=val;
        LOGGER.info("{} : result {}",threadName,val);
    }

    public void divi(int val,String threadName){
        LOGGER.info("{} : {} divi {}",threadName,val);
        value /=val;
        LOGGER.info("{} : result {}",threadName,val);
    }

    public void mathaction(String threadName){

        add(1,threadName);
        sub(1,threadName);

        multi(2,threadName);
        divi(2,threadName);
    }

    public void proccess(String threadName) throws InterruptedException {
        while (!threadNotify.hasLock()){
            LOGGER.info("线程 ：{} 等待处理业务!",threadName);
            threadNotify.dowait();
        }
        threadNotify.setLock(false);
        LOGGER.info("线程 ：{} 开始处理业务!",threadName);
        Thread.sleep(1000L);
        LOGGER.info("线程 ：{} 处理业务完成!",threadName);
        threadNotify.setLock(true);
        threadNotify.donotify();
    }
}
